package com.utils;


import lombok.Data;

@Data
public class JsonData {

    //返回的状态码
    private int code;
    //返回的结果
    private Object obj;
    //回馈的信息
    private String msg;

    public JsonData(){}

    public JsonData(int code, String msg) {
        code = code;
        this.msg = msg;
    }

    public JsonData(int code, Object obj) {
        this.code = code;
        this.obj = obj;
    }

    public JsonData(int code, Object obj, String msg) {
        code = code;
        this.obj = obj;
        this.msg = msg;
    }

    /**
     * 成功返回空信息
     * @return
     */
    public static JsonData buildSuccess(){return new JsonData();}

    /**
     * 成功返回成功的对象
     * @param obj
     * @return
     */
    public static JsonData buildSuccess(Object obj){
        return new JsonData(0,obj);
    }

    /**
     * 失败返回提示信息
     * @param msg
     * @return
     */
    public static JsonData buildError(String msg){
        return new JsonData(-1,msg);
    }

    /**
     * 返回对应的错误码和提示信息
     * @param code
     * @param msg
     * @return
     */
    public static JsonData buildError(int code,String msg){
        return new JsonData(code,msg);
    }


}
